﻿using System.Collections.ObjectModel;
using System.Windows.Data;

using Odebrecht.WpfApplication.Models;
using Odebrecht.WpfApplication.TarefaServiceReference;

namespace Odebrecht.WpfApplication.ViewModels
{
    public class TarefaViewModel
    {
        #region Fields

        protected readonly CollectionViewSource _collectionOfTarefa;
        protected readonly ObservableCollection<TarefaModel> _listOfTarefa;

        #endregion Fields

        #region Constructors

        public TarefaViewModel()
        {
            _listOfTarefa = new ObservableCollection<TarefaModel>();
            _collectionOfTarefa = new CollectionViewSource();
            _collectionOfTarefa.Source = _listOfTarefa;
        }

        #endregion Constructors

        #region Properties

        public CollectionViewSource CollectionOfTarefa
        {
            get
            {
                return _collectionOfTarefa;
            }
        }

        #endregion Properties

        #region Methods

        public void LoadListOfTarefa()
        {
            var client = new TarefaServiceClient();
            var result = client.GetTarefas();

            _listOfTarefa.Clear();

            foreach (var item in result)
            {
                _listOfTarefa.Add(new TarefaModel
                {
                    TarefaId = item.TarefaId
                    , Nome = item.Nome
                    , Duracao = item.Duracao
                    , Estimada = item.Estimada
                    , ExibirNaLinhaDoTempo = item.ExibirNaLinhaDoTempo
                    , Inativo = item.Inativo
                    , Inicio = item.Inicio
                    , OcultarBarra = item.OcultarBarra
                    , RepresentacaoAcumulada = item.RepresentacaoAcumulada
                    , Termino = item.Termino
                });
            }
        }

        #endregion Methods
    }
}